Option Strict Off
Option Explicit On

Imports BCS.MotorActivacion.Base

Public Class Parametros
    Inherits Lista

    Private m_Lista As Hashtable
    Private m_LstPadres As Hashtable

    Public ReadOnly Property Item() As Parametro
        Get
            Item = m_Item
        End Get
    End Property

    Public Sub AddItem(ByVal NewVal As Parametro, Optional ByVal Refresh As Boolean = True)
        Dim Key As String

        Key = NewVal.Key
        If Not m_Lista.Contains(Key) Then
            Select Case NewVal.TipoDato
                Case Declaraciones.TypeDataParameterEnum.TypeDataParameterComposed, Declaraciones.TypeDataParameterEnum.TypeDataParameterOcurrence
                    m_LstPadres.Add(Key, Key)
            End Select

            m_Lista.Add(Key, NewVal)
            If Refresh Then
                toRefresh()
            End If
        End If
    End Sub

    Public Overrides Sub Remove(ByVal Key As String, ByVal Refresh As Boolean)
        Dim Itm As Parametro

        If m_Lista.Contains(Key) Then
            Itm = m_Lista.Item(Key)
            Select Case Itm.TipoDato
                Case Declaraciones.TypeDataParameterEnum.TypeDataParameterComposed, Declaraciones.TypeDataParameterEnum.TypeDataParameterOcurrence
                    m_LstPadres.Remove(Key)
            End Select

            m_Lista.Remove(Key)
            If Refresh = True Then
                toRefresh()
            End If
        End If
    End Sub

    Public Overrides Sub RemoveAll(ByVal Refresh As Boolean)
        m_Lista.Clear()
        m_LstPadres.Clear()

        If Refresh = True Then
            toRefresh()
        End If
    End Sub

    Public Function GetItem(ByVal Key As String) As Parametro
        If m_List.Contains(Key) Then
            Return m_Lista.Item(Key)
        Else
            Return Nothing
        End If
    End Function

    Public Function GetList() As Object
        GetList = m_Lista.Keys
    End Function

    Public Function NodesCount() As Integer
        NodesCount = m_LstPadres.Count
    End Function

    Public Function GetNodesList() As Object
        Return m_LstPadres.Keys
    End Function

    Public Function Clone() As Parametros
        Dim i As Short
        Dim auxKeys As Object
        Dim newItems As Parametros
        Dim auxItem As Parametro
        Dim newItem As Parametro

        newItems = New Parametros

        auxKeys = m_Lista.Keys
        For i = LBound(auxKeys) To UBound(auxKeys)

            auxItem = m_Lista.Item(auxKeys(i))
            newItem = auxItem.Clone

            newItems.AddItem(newItem, False)
        Next

        newItems.toRefresh()

        Clone = newItems
    End Function

    Public Sub New()
        MyBase.New()

        m_LstPadres = New Hashtable
    End Sub

    Protected Overrides Sub Finalize()
        m_LstPadres = Nothing

        MyBase.Finalize()
    End Sub
End Class